import androidx.compose.desktop.ui.tooling.preview.Preview
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.PointerEventType
import androidx.compose.ui.input.pointer.onPointerEvent
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.*


@OptIn(ExperimentalComposeUiApi::class)
@Composable
@Preview
fun App() {
    var isHovered1 by remember { mutableStateOf(false) }
    var isHovered2 by remember { mutableStateOf(false) }
    var isHovered3 by remember { mutableStateOf(false) }
    var isHovered4 by remember { mutableStateOf(false) }
    var isHovered5 by remember { mutableStateOf(false) }
    var isHovered6 by remember { mutableStateOf(false) }
    var isHovered7 by remember { mutableStateOf(false) }
    var isHovered8 by remember { mutableStateOf(false) }
    var isHovered9 by remember { mutableStateOf(false) }
    val baseColor = Color(0xfff0f0f0)
    val hoverColor = Color(0xffe5f3ff)
    MaterialTheme() {

        Column(
            modifier = Modifier.fillMaxWidth().background(baseColor),
        ) {
            Row(
                horizontalArrangement = Arrangement.Start,
                verticalAlignment = Alignment.CenterVertically,
                modifier = Modifier.height(80.dp).fillMaxWidth()
            ) {
                Column(
                    horizontalAlignment = Alignment.CenterHorizontally,
                    verticalArrangement = Arrangement.Center,
                    modifier = Modifier
                        .height(80.dp).width(80.dp)
                        .background(if (isHovered1) hoverColor else baseColor)
                        .onPointerEvent(PointerEventType.Move) {
                        }
                        .onPointerEvent(PointerEventType.Enter) {
                            isHovered1 = true
                        }
                        .onPointerEvent(PointerEventType.Exit) {
                            isHovered1 = false
                        }
                ) {
                    Image(
                        painter = painterResource("/static/images/connect.png"),
                        contentDescription = "icon",
                        modifier = Modifier.height(32.dp).width(32.dp)
                    )
                    Text("连接")
                }
                Column(
                    horizontalAlignment = Alignment.CenterHorizontally,
                    verticalArrangement = Arrangement.Center,
                    modifier = Modifier
                        .height(80.dp).width(80.dp)
                        .background(if (isHovered2) hoverColor else baseColor)
                        .onPointerEvent(PointerEventType.Move) {
                        }
                        .onPointerEvent(PointerEventType.Enter) {
                            isHovered2 = true
                        }
                        .onPointerEvent(PointerEventType.Exit) {
                            isHovered2 = false
                        }
                ) {
                    Image(
                        painter = painterResource("/static/images/query.png"),
                        contentDescription = "icon",
                        modifier = Modifier.height(32.dp).width(32.dp)
                    )
                    Text("新建查询")
                }
                Column(
                    horizontalAlignment = Alignment.CenterHorizontally,
                    verticalArrangement = Arrangement.Center,
                    modifier = Modifier
                        .height(80.dp).width(80.dp)
                        .background(if (isHovered3) hoverColor else baseColor)
                        .onPointerEvent(PointerEventType.Move) {
                        }
                        .onPointerEvent(PointerEventType.Enter) {
                            isHovered3 = true
                        }
                        .onPointerEvent(PointerEventType.Exit) {
                            isHovered3 = false
                        }
                ) {
                    Image(
                        painter = painterResource("/static/images/table.png"),
                        contentDescription = "icon",
                        modifier = Modifier.height(32.dp).width(32.dp)
                    )
                    Text("表")
                }
                Column(
                    horizontalAlignment = Alignment.CenterHorizontally,
                    verticalArrangement = Arrangement.Center,
                    modifier = Modifier
                        .height(80.dp).width(80.dp)
                        .background(if (isHovered4) hoverColor else baseColor)
                        .onPointerEvent(PointerEventType.Move) {
                        }
                        .onPointerEvent(PointerEventType.Enter) {
                            isHovered4 = true
                        }
                        .onPointerEvent(PointerEventType.Exit) {
                            isHovered4 = false
                        }
                ) {
                    Image(
                        painter = painterResource("/static/images/view.png"),
                        contentDescription = "icon",
                        modifier = Modifier.height(32.dp).width(32.dp)
                    )
                    Text("视图")
                }
                Column(
                    horizontalAlignment = Alignment.CenterHorizontally,
                    verticalArrangement = Arrangement.Center,
                    modifier = Modifier
                        .height(80.dp).width(80.dp)
                        .background(if (isHovered5) hoverColor else baseColor)
                        .onPointerEvent(PointerEventType.Move) {
                        }
                        .onPointerEvent(PointerEventType.Enter) {
                            isHovered5 = true
                        }
                        .onPointerEvent(PointerEventType.Exit) {
                            isHovered5 = false
                        }
                ) {
                    Image(
                        painter = painterResource("/static/images/func.png"),
                        contentDescription = "icon",
                        modifier = Modifier.height(32.dp).width(32.dp)
                    )
                    Text("函数")
                }
                Column(
                    horizontalAlignment = Alignment.CenterHorizontally,
                    verticalArrangement = Arrangement.Center,
                    modifier = Modifier
                        .height(80.dp).width(80.dp)
                        .background(if (isHovered6) hoverColor else baseColor)
                        .onPointerEvent(PointerEventType.Move) {
                        }
                        .onPointerEvent(PointerEventType.Enter) {
                            isHovered6 = true
                        }
                        .onPointerEvent(PointerEventType.Exit) {
                            isHovered6 = false
                        }
                ) {
                    Image(
                        painter = painterResource("/static/images/user.png"),
                        contentDescription = "icon",
                        modifier = Modifier.height(32.dp).width(32.dp)
                    )
                    Text("用户")
                }
                Column(
                    horizontalAlignment = Alignment.CenterHorizontally,
                    verticalArrangement = Arrangement.Center,
                    modifier = Modifier
                        .height(80.dp).width(80.dp)
                        .background(if (isHovered7) hoverColor else baseColor)
                        .onPointerEvent(PointerEventType.Move) {
                        }
                        .onPointerEvent(PointerEventType.Enter) {
                            isHovered7 = true
                        }
                        .onPointerEvent(PointerEventType.Exit) {
                            isHovered7 = false
                        }
                ) {
                    Image(
                        painter = painterResource("/static/images/query.png"),
                        contentDescription = "icon",
                        modifier = Modifier.height(32.dp).width(32.dp)
                    )
                    Text("查询")
                }
                Column(
                    horizontalAlignment = Alignment.CenterHorizontally,
                    verticalArrangement = Arrangement.Center,
                    modifier = Modifier
                        .height(80.dp).width(80.dp)
                        .background(if (isHovered8) hoverColor else baseColor)
                        .onPointerEvent(PointerEventType.Move) {
                        }
                        .onPointerEvent(PointerEventType.Enter) {
                            isHovered8 = true
                        }
                        .onPointerEvent(PointerEventType.Exit) {
                            isHovered8 = false
                        }
                ) {
                    Image(
                        painter = painterResource("/static/images/backups.png"),
                        contentDescription = "icon",
                        modifier = Modifier.height(32.dp).width(32.dp)
                    )
                    Text("备份")
                }
                Column(
                    horizontalAlignment = Alignment.CenterHorizontally,
                    verticalArrangement = Arrangement.Center,
                    modifier = Modifier
                        .height(80.dp).width(80.dp)
                        .background(if (isHovered9) hoverColor else baseColor)
                        .onPointerEvent(PointerEventType.Move) {
                        }
                        .onPointerEvent(PointerEventType.Enter) {
                            isHovered9 = true
                        }
                        .onPointerEvent(PointerEventType.Exit) {
                            isHovered9 = false
                        }
                ) {
                    Image(
                        painter = painterResource("/static/images/cron.png"),
                        contentDescription = "icon",
                        modifier = Modifier.height(32.dp).width(32.dp)
                    )
                    Text("自动运行")
                }
            }
        }

    }
}

fun main() = application {
    val icon = painterResource("/static/images/icon.png")



    Window(
        onCloseRequest = ::exitApplication,
        title = "Poverty", // App名称
        icon = icon, // App图标
        state = rememberWindowState(placement = WindowPlacement.Floating), // 窗口状态
        resizable = true, // 是否可以调整窗口大小
        undecorated = false, // 是否显示窗口边框
    ) {
        App()
    }
}
